import variables from '@/styles/element-variables.scss'
import defaultSettings from '@/settings'
import {getLocalStorage, setLocalStorage} from '@/utils/storage'
const { theme, showSettings, tagsView, fixedHeader, sidebarLogo } = getLocalStorage('system-settings') || defaultSettings

const state = {
  theme: theme || variables.theme,
  showSettings: showSettings,
  tagsView: tagsView,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value
      setLocalStorage('system-settings', state)
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
